package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.bean.TopicBean;
import com.project.bean.UserBean;
import com.project.service.ITopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@RestController
@RequestMapping("topic")
public class TopicController {
    @Autowired
    private ITopicService service;



    @RequestMapping("findById")
    public TopicBean findById(int id){
       return service.findById(id);
    }

    @RequestMapping("add")
    public String add(String contents, int channelId, HttpServletRequest req){
      UserBean userBean=(UserBean)req.getSession().getAttribute("loginUser");
    service.add(new TopicBean(contents,userBean.getName(),channelId));
    return "ok";
    }

    @RequestMapping("cutByItem")
    public PageInfo<TopicBean> findByItem(@RequestParam(value = "pageNO",defaultValue = "1") int NO,
                                          int channelId, String name, String auth,  LocalDate startDate,LocalDate endDate){

        return service.cutByItem(NO,channelId,name,auth,startDate,endDate);
    }

}
